using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Resource.@string;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using Microsoft.Phone.Controls;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
namespace MicroMsg.UI.Page
{
	public class ListSearchPage : BasePage
	{
		private const string TAG = "ListSearchPage";
		private const int cNListHFocus = 400;
		private const int cNListHUnFocus = 700;
		private const uint cNTxtInMoveAniDuaration = 600u;
		private SearchAlgorithm searchAlgorithm_0;
		private string lastSearchWord;
		public static List<ListSearchItem> AllShakePeopleItems = new List<ListSearchItem>();
		private EventWatcher getHeadImgWatcher;
		private Storyboard mSbTxtInMove;
		private bool mBIsBacked;
		internal Grid LayoutRoot;
		internal PhoneTextBox txtIn;
		internal ListBox listBoxPeople;
		internal TextBlock txtNoresult;
		private bool _contentLoaded;
		public ListSearchPage()
		{
			if (ListSearchPage.AllShakePeopleItems != null)
			{
				ListSearchPage.AllShakePeopleItems.Clear();
			}
			this.InitializeComponent();
		}
		protected override void OnPageLoaded(object sender, RoutedEventArgs e)
		{
			base.OnPageLoaded(sender, e);
			this.txtIn.Focus();
			this.doSearch(this.txtIn.get_Text());
			Log.smethod_5("ListSearchPage", "Page_Loaded");
			this.InitWatcher();
		}
		protected override void OnPageUnLoaded(object sender, RoutedEventArgs e)
		{
			base.OnPageUnLoaded(sender, e);
			Log.smethod_5("ListSearchPage", "Page_Unloaded");
			this.UnitWatcher();
		}
		protected override void OnPageIn(object[] object_0)
		{
			Log.smethod_5("ListSearchPage", "OnPageIn");
			if (object_0 == null || object_0.Length == 0 || object_0[0].GetType() != typeof(SearchAlgorithm))
			{
				Log.smethod_5("ListSearchPage", "OnPageIn param[SearchAlgorithm] is null");
				base.GoBack();
			}
			this.searchAlgorithm_0 = (object_0[0] as SearchAlgorithm);
			this.startTxtInMove(false);
			this.txtIn.Hint = " " + strings.COM_Search;
		}
		protected override void OnPageOut()
		{
			Log.smethod_5("ListSearchPage", "OnPageOut");
		}
		protected override void OnPageBack()
		{
			Log.smethod_5("ListSearchPage", "OnPageBack");
		}
		private void InitWatcher()
		{
			if (this.getHeadImgWatcher == null)
			{
				this.getHeadImgWatcher = new EventWatcher(this, null, new EventHandlerDelegate(this.onEventHandlerGetHeadImg));
				EventCenter.registerEventWatcher(EventConst.ON_MGR_HEAD_IMG_READY, this.getHeadImgWatcher);
			}
		}
		private void UnitWatcher()
		{
			if (this.getHeadImgWatcher != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_MGR_HEAD_IMG_READY, this.getHeadImgWatcher);
				this.getHeadImgWatcher = null;
			}
		}
		private void onEventHandlerGetHeadImg(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			Log.smethod_5("ListSearchPage", "onEventHandlerGetHeadImg");
			List<string> listObject = evtArgs.getListObject<string>();
			if (listObject == null)
			{
				return;
			}
			using (List<string>.Enumerator enumerator = listObject.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					string current = enumerator.get_Current();
					if (current != null && current.GetType() == typeof(string))
					{
						using (List<ListSearchItem>.Enumerator enumerator2 = ListSearchPage.AllShakePeopleItems.GetEnumerator())
						{
							while (enumerator2.MoveNext())
							{
								ListSearchItem current2 = enumerator2.get_Current();
								if (current2 != null && current2.ItemObject != null && current2.ItemObject.mObject != null && current == HeadImgMgr.getUserName(current2.ItemObject.mObject))
								{
									ImageSource cacheHeadImage = HeadImgMgr.getCacheHeadImage(current2.ItemObject.mObject);
									if (cacheHeadImage != null && cacheHeadImage != HeadImgMgr.defaultHeadImage)
									{
										current2.imgHead.set_Source(cacheHeadImage);
									}
								}
							}
						}
					}
				}
			}
		}
		private void Onxxx(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (evtArgs == null)
			{
				return;
			}
		}
		private void txtIn_TextChanged(object sender, TextChangedEventArgs e)
		{
			if (string.IsNullOrEmpty(this.txtIn.get_Text()))
			{
				base.Focus();
				this.txtIn.Focus();
			}
			this.doSearch(this.txtIn.get_Text());
		}
		private void txtIn_GotFocus(object sender, RoutedEventArgs e)
		{
			this.listBoxPeople.set_Height(400.0);
		}
		private void txtIn_LostFocus(object sender, RoutedEventArgs e)
		{
			this.listBoxPeople.set_Height(700.0);
		}
		private void listItemClick(object sender, object object_0)
		{
		}
		private void initUI()
		{
		}
		private void doSearch(string searchWord)
		{
			if (this.lastSearchWord == searchWord)
			{
				return;
			}
			this.lastSearchWord = searchWord;
			base.get_Dispatcher().BeginInvoke(delegate
			{
				Log.smethod_5("SearchAlgorithm Test", "SearchAlgorithm Start");
				List<SearchRetItem> searchRet = this.searchAlgorithm_0.GetSearchRet(searchWord);
				Log.smethod_5("SearchAlgorithm Test", "SearchAlgorithm End");
				if (searchRet != null && searchRet.get_Count() != 0)
				{
					this.txtNoresult.set_Visibility(1);
				}
				else
				{
					this.txtNoresult.set_Visibility(0);
				}
				this.listBoxPeople.set_ItemsSource(searchRet);
			});
		}
		private void startTxtInMove(bool bIsGoBack = false)
		{
			this.txtIn.set_Visibility(0);
			CompositeTransform compositeTransform = new CompositeTransform();
			this.txtIn.set_RenderTransform(compositeTransform);
			this.txtIn.set_RenderTransformOrigin(new Point(0.5, 0.5));
			Storyboard storyboard = new Storyboard();
			uint num = 600u;
			DoubleAnimation doubleAnimation;
			if (bIsGoBack)
			{
				doubleAnimation = this.createAnimation(0.0, -2.0 * this.txtIn.get_Height(), compositeTransform, "TranslateY", num / 3u);
			}
			else
			{
				doubleAnimation = this.createAnimation(-2.0 * this.txtIn.get_Height(), 0.0, compositeTransform, "TranslateY", num);
			}
			storyboard.get_Children().Add(doubleAnimation);
			this.mSbTxtInMove = storyboard;
			if (bIsGoBack)
			{
				base.get_Dispatcher().BeginInvoke(delegate
				{
					base.GoBack();
				});
				this.mSbTxtInMove.add_Completed(new EventHandler(this.mSbTxtInMove_Completed));
			}
			this.mSbTxtInMove.Begin();
		}
		private void mSbTxtInMove_Completed(object sender, EventArgs e)
		{
		}
		private void stopTxtInMoveAni()
		{
			if (this.mSbTxtInMove != null)
			{
				this.mSbTxtInMove.Stop();
			}
			this.mSbTxtInMove = null;
		}
		private DoubleAnimation createAnimation(double from, double double_0, DependencyObject target, string property, uint duration)
		{
			new Storyboard();
			DoubleAnimation doubleAnimation = new DoubleAnimation();
			doubleAnimation.set_From(new double?(from));
			doubleAnimation.set_To(new double?(double_0));
			doubleAnimation.set_Duration(TimeSpan.FromMilliseconds(duration));
			Storyboard.SetTarget(doubleAnimation, target);
			Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath(property, new object[0]));
			return doubleAnimation;
		}
		protected override void OnBackKeyPress(CancelEventArgs cancelEventArgs_0)
		{
			if (this.mBIsBacked)
			{
				return;
			}
			this.mBIsBacked = true;
			this.startTxtInMove(true);
			cancelEventArgs_0.set_Cancel(true);
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/ListSearchHelper/ListSearchPage.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.txtIn = (PhoneTextBox)base.FindName("txtIn");
			this.listBoxPeople = (ListBox)base.FindName("listBoxPeople");
			this.txtNoresult = (TextBlock)base.FindName("txtNoresult");
		}
	}
}
